﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using PMS.Web.Framework.Mvc.Routing;
using PMS.Web.Framework.StartupCfgs.StartupSetups;

namespace PMS.Web.MvcRouteConfigs
{
    public partial class BackendRouteProvider : IRouteProvider
    {
        #region Methods

        /// <summary>
        /// Register routes
        /// </summary>
        /// <param name="endpointRouteBuilder">Route builder</param>
        public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
        {
            //var langservice = endpointRouteBuilder.ServiceProvider.GetRequiredService<ILanguageService>();
            //var languages = langservice.GetAllLanguages().ToList();
            //var pattern = "{language:lang=" + languages.FirstOrDefault().LanguageCode + "?}";
            ////Backend Default Home
            //endpointRouteBuilder.MapControllerRoute(
            //    name: "BackendDefault",
            //    pattern: "{controller=BackendHome}/{action=Index}/{id?}");
            //BackendLogin
            endpointRouteBuilder.MapControllerRoute("BackendLogin", "/backend/login",
                new { controller = "BackendLogin", action = "Login" });
            endpointRouteBuilder.MapControllerRoute("BackendLogout", "/backend/logout",
                new { controller = "BackendLogin", action = "Logout" });
            //Backend ScheduleTask /scheduletask/runtask matches ControllerName/ActionName, no need to config
            endpointRouteBuilder.MapControllerRoute("BackendHome", "/backend/home",
                new { controller = "BackendHome", action = "Home" });

            #region SystemManage
            endpointRouteBuilder.MapControllerRoute("SystemModuleListView", "/backend/systemmanage/systemmodule/list",
                new { controller = "SystemModuleManage", action = "SystemModuleListView" });
            endpointRouteBuilder.MapControllerRoute("SystemModuleEditView", "/backend/systemmanage/systemmodule/edit",
                new { controller = "SystemModuleManage", action = "SystemModuleEditView" });
            endpointRouteBuilder.MapControllerRoute("SystemModuleAuthView", "/backend/systemmanage/systemmodule/auth",
                new { controller = "SystemModuleManage", action = "SystemModuleAuthView" });
            endpointRouteBuilder.MapControllerRoute("ScheduleTaskTrigger", DefaultRoutePath.ScheduleTaskPath,
                new { controller = "ScheduleTaskManage", action = "RunTask" });
            endpointRouteBuilder.MapControllerRoute("ScheduleTaskListView", "/backend/systemmanage/scheduletask/list",
                new { controller = "ScheduleTaskManage", action = "ScheduleTaskListView" });
            #endregion

            #region CustomerManage
            endpointRouteBuilder.MapControllerRoute("OnLineCustomerListView", "/backend/customermange/onlinecustomer/list",
                new { controller = "CustomerManage", action = "OnLineCustomerListView" });
            endpointRouteBuilder.MapControllerRoute("CustomerListView", "/backend/customermange/customer/list",
                new { controller = "CustomerManage", action = "CustomerListView" });
            endpointRouteBuilder.MapControllerRoute("CustomerEditView", "/backend/customermange/customer/edit",
                new { controller = "CustomerManage", action = "CustomerEditView" });
            endpointRouteBuilder.MapControllerRoute("CustomerAssignRoleView", "/backend/customermange/customer/assignrole",
                new { controller = "CustomerManage", action = "CustomerAssignRoleView" });
            endpointRouteBuilder.MapControllerRoute("BackendCustomerProfile", "/backend/customermange/customer/myprofile",
                new { controller = "CustomerManage", action = "CustomerProfile" });
            endpointRouteBuilder.MapControllerRoute("BackendChangeCustomerAccount", "/backend/customermange/customer/changeaccount",
                new { controller = "CustomerManage", action = "ChangeCustomerAccount" });
            #endregion

            #region ArticlesManage
            endpointRouteBuilder.MapControllerRoute("ArticleColumnListView", "/backend/articlesmanage/navimenu/list",
                new { controller = "ArticlesManage", action = "NaviMenuListView" });
            endpointRouteBuilder.MapControllerRoute("ArticleColumnDetailEditView", "/backend/articlesmanage/navimenu/edit",
                new { controller = "ArticlesManage", action = "NaviMenuDetailEditView" });
            #endregion
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets a priority of route provider
        /// </summary>
        public int Priority => 1;

        #endregion

    }
}
